// pages/tuijian/tuijian.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    banner: [],
    posts: [],
    code: 60906,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '正在加载~',
    })
    let _this = this;
    wx.request({
      url: "https://app.vmovier.com/apiv3/index/index",
      success(res) {
        wx.hideLoading({
          success: (res) => {},
        })
        
        _this.setData({
          banner: res.data.data.banner.list,
          posts: res.data.data.posts.list
        })
       
      }
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showLoading({
      title: '加载更多~',
    })
    let _this = this
    wx.request({
      url: `https://app.vmovier.com/apiv3/index/getIndexPosts/lastid/${_this.data.code}`,
      success(res) {
        wx.hideLoading({
          success: (res) => {},
        })
        let arr = res.data.data.list.concat(_this.data.posts)
        let code1 = res.data.data.lastid
        _this.setData({
          posts: arr,
          code: code1
        })
      }
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '加载更多~',
    })
    let _this = this
    wx.request({
      url: `https://app.vmovier.com/apiv3/index/getIndexPosts/lastid/${_this.data.code}`,
      success(res) {
        wx.hideLoading({
          success: (res) => {},
        })
       
        let arr = _this.data.posts.concat(res.data.data.list)
        let code1 = res.data.data.lastid
        _this.setData({
          posts: arr,
          code: code1
        })
      }
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (from,target,url) {
      return{
        title:"八四给你分享了一个精彩的视频！",
        imageUrl:this.data.posts.image
      }
  },
  onShareTimeline(){
    return{
      title:"分享到朋友圈",
      imageUrl:this.data.posts.image
    }
  },
  foo() {
    wx.navigateTo({
      url: '/pages/search/search',
    })
  }
})